package CAD;

import j3d.J3D;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import operationSolids.OperationBlock;

import visualCAD.NewProjectVisual;

import features.Block;

public class NewProject extends NewProjectVisual implements ActionListener {
	  
	MainFrame adaptee;
	J3D j3d;
	
 	public NewProject(MainFrame adaptee){
		this.adaptee = adaptee;
		initListeners();
		j3d = new J3D(this.j3dPannel);
		setVisible(true);
	}
	
	public void initListeners(){
	
		this.okButton.addActionListener(this);
		this.previewButton.addActionListener(this);
		this.cancelButton.addActionListener(this);
		}

	@Override
	public void actionPerformed(ActionEvent evt) {
		Object source = evt.getSource();
		
		if(source.equals(okButton)){
		adaptee.block = new Block(Float.parseFloat(xSpinner.getValue().toString()),
				Float.parseFloat(ySpinner.getValue().toString()),
				Float.parseFloat(zSpinner.getValue().toString()),
				Float.parseFloat(toleranceSpinner.getValue().toString()),
				nameTextField.getText());
		(adaptee.getJ3d()).addSolid(MainFrame.block.block);
		adaptee.refreshJTree();
		adaptee.setIconsEnable(); 
		dispose();
    	}
		if(source.equals(previewButton)){
			j3d.setPreviewMode();
			j3d.removeSolid();
			adaptee.block = new Block(Float.parseFloat(xSpinner.getValue().toString()),
					Float.parseFloat(ySpinner.getValue().toString()),
					Float.parseFloat(zSpinner.getValue().toString()),
					Float.parseFloat(toleranceSpinner.getValue().toString()),
					nameTextField.getText());
			j3d.addSolid(
					adaptee.block.block);
		}
		if(source.equals(cancelButton)){
		dispose();
	    }
	}
}

